﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

namespace Microhard.JHSSO.WebUI
{
    public partial class rUrl : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //获得去要跳转的地址
            var url = Request.QueryString["rUrl"];
            if (string.IsNullOrEmpty(url))
            {
                Response.Write("参数错误，01");
                Response.End();
            }
            if (!ConfigurationManager.AppSettings.AllKeys.Contains("supprj"))
            {
                Response.Write("参数错误，02");
                Response.End();
            }
            url = ConfigurationManager.AppSettings["supprj"];
            //拼装加密串
            if (!ConfigurationManager.AppSettings.AllKeys.Contains("EncKey"))
            {
                Response.Write("参数错误，03");
                Response.End();
            }
            string key = ConfigurationManager.AppSettings["EncKey"];
            var userCode = Session["UserCode"];
            if (userCode == null)
            {
                Response.Write("参数错误，04");
                Response.End();
            }
            var strUC = userCode.ToString();
            if (string.IsNullOrEmpty(strUC))
            {
                Response.Write("参数错误，05");
                Response.End();
            }
            string encStr = EncDec.Encrypt(strUC, key);
            encStr = encStr.Replace("+", " ");
            string finUrl = url + "?key=" + HttpUtility.UrlEncode(encStr);
            Response.Redirect(finUrl, "_blank", string.Empty);
        }
    }
}